﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_siconide_packing
{
    public DAL_tbl_siconide_packing()
    {

    }



    public List<tbl_siconide_packing> select(int ID)
    {
        List<tbl_siconide_packing> list = new List<tbl_siconide_packing>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,PREVIOUS_PROCESS,PALLA_MILLJET_RUN_NUMBER,Charge_Number,Drum_Number,Gross_Weight,Net_Weight,SicoNide_Purity_Grade,SicoNide_SSA,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_packing where ID=@ID";
        cmd.Parameters.AddWithValue("@ID", ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_packing()
            {
                ID = Convert.ToInt32(dr["ID"]),
                PREVIOUS_PROCESS = dr["PREVIOUS_PROCESS"].ToString(),
                PALLA_MILLJET_RUN_NUMBER = dr["PALLA_MILLJET_RUN_NUMBER"].ToString(),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Drum_Number = dr["Drum_Number"].ToString(),
                Gross_Weight = Convert.ToDecimal(dr["Gross_Weight"]),
                Net_Weight = Convert.ToDecimal(dr["Net_Weight"]),
                SicoNide_Purity_Grade = dr["SicoNide_Purity_Grade"].ToString(),
                SicoNide_SSA = Convert.ToDecimal(dr["SicoNide_SSA"]),
                Remark = dr["Remark"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_siconide_packing> selectAll()
    {
        List<tbl_siconide_packing> list = new List<tbl_siconide_packing>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,PREVIOUS_PROCESS,PALLA_MILLJET_RUN_NUMBER,Charge_Number,Drum_Number,Gross_Weight,Net_Weight,SicoNide_Purity_Grade,SicoNide_SSA,Remark,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_packing Order By ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_packing()
            {
                ID = Convert.ToInt32(dr["ID"]),
                PREVIOUS_PROCESS = dr["PREVIOUS_PROCESS"].ToString(),
                PALLA_MILLJET_RUN_NUMBER = dr["PALLA_MILLJET_RUN_NUMBER"].ToString(),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Drum_Number = dr["Drum_Number"].ToString(),
                Gross_Weight = Convert.ToDecimal(dr["Gross_Weight"]),
                Net_Weight = Convert.ToDecimal(dr["Net_Weight"]),
                SicoNide_Purity_Grade = dr["SicoNide_Purity_Grade"].ToString(),
                SicoNide_SSA = Convert.ToDecimal(dr["SicoNide_SSA"]),
                Remark = dr["Remark"].ToString(),                
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }

    public DataTable selectAllForGrid()
    {
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = @"Select ID,PREVIOUS_PROCESS,PALLA_MILLJET_RUN_NUMBER,Charge_Number,Drum_Number,Gross_Weight,Net_Weight,SicoNide_Purity_Grade,SicoNide_SSA,Remark,CASE WHEN IS_ACTIVE =1 THEN 'True' ELSE 'False' END as 'IS_ACTIVE',CREATED_BY,CREATED_DATE as CREATED_DATE,UPDATED_BY,UPDATED_DATE as UPDATED_DATE from tbl_siconide_packing Order By ID desc";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        return dt;
    }

    public int insert(String PREVIOUS_PROCESS, String PALLA_MILLJET_RUN_NUMBER, Decimal Charge_Number, String Drum_Number, Decimal Gross_Weight, Decimal Net_Weight, String SicoNide_Purity_Grade, Decimal SicoNide_SSA, String Remark, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_siconide_packing(PREVIOUS_PROCESS, PALLA_MILLJET_RUN_NUMBER, Charge_Number, Drum_Number, Gross_Weight, Net_Weight, SicoNide_Purity_Grade, SicoNide_SSA, Remark, CREATED_BY, CREATED_DATE)
                        values(@PREVIOUS_PROCESS, @PALLA_MILLJET_RUN_NUMBER, @Charge_Number, @Drum_Number, @Gross_Weight, @Net_Weight, @SicoNide_Purity_Grade, @SicoNide_SSA, @Remark, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);
        cmd.Parameters.AddWithValue("@PREVIOUS_PROCESS", PREVIOUS_PROCESS);
        cmd.Parameters.AddWithValue("@PALLA_MILLJET_RUN_NUMBER", PALLA_MILLJET_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Drum_Number", Drum_Number);
        cmd.Parameters.AddWithValue("@Gross_Weight", Gross_Weight);
        cmd.Parameters.AddWithValue("@Net_Weight", Net_Weight);
        cmd.Parameters.AddWithValue("@SicoNide_Purity_Grade", SicoNide_Purity_Grade);
        cmd.Parameters.AddWithValue("@SicoNide_SSA", SicoNide_SSA);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ID, String PREVIOUS_PROCESS, String PALLA_MILLJET_RUN_NUMBER, Decimal Charge_Number, String Drum_Number, Decimal Gross_Weight, Decimal Net_Weight, String SicoNide_Purity_Grade, Decimal SicoNide_SSA, String Remark, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_siconide_packing SET PREVIOUS_PROCESS=@PREVIOUS_PROCESS, PALLA_MILLJET_RUN_NUMBER=@PALLA_MILLJET_RUN_NUMBER, Charge_Number=@Charge_Number, Drum_Number=@Drum_Number, Gross_Weight=@Gross_Weight, Net_Weight=@Net_Weight, SicoNide_Purity_Grade=@SicoNide_Purity_Grade, SicoNide_SSA=@SicoNide_SSA, Remark=@Remark, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("@PREVIOUS_PROCESS", PREVIOUS_PROCESS);
        cmd.Parameters.AddWithValue("@PALLA_MILLJET_RUN_NUMBER", PALLA_MILLJET_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Drum_Number", Drum_Number);
        cmd.Parameters.AddWithValue("@Gross_Weight", Gross_Weight);
        cmd.Parameters.AddWithValue("@Net_Weight", Net_Weight);
        cmd.Parameters.AddWithValue("@SicoNide_Purity_Grade", SicoNide_Purity_Grade);
        cmd.Parameters.AddWithValue("@SicoNide_SSA", SicoNide_SSA);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_siconide_packing WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}